package com.joinpay.service.impl;


import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.joinpay.dao.UserDao;
import com.joinpay.model.User;
import com.joinpay.service.UserService;
import com.joinpay.util.ManageTimeUtil;

import ch.qos.logback.core.util.TimeUtil;

@Service
public class UserServiceImpl implements UserService{
	
	/**
	 * 自动装载
	 */
	@Resource
	private UserDao userDao;

	@Override
	@Transactional
	public int insertUser(Map map) {
		// TODO Auto-generated method stub
		User user = new User();
		String currentUser = String.valueOf(map.get("currentUser"));
		String currentTime = ManageTimeUtil.getCurrentTime();
		user.setUsername(String.valueOf(map.get("username")));
		user.setPassword(String.valueOf(map.get("password")));
		user.setNickname(String.valueOf(map.get("nickname")));
		user.setDepartID(String.valueOf(map.get("departID")));
		user.setDepartName(String.valueOf(map.get("groupName")));
		user.setPower(Integer.parseInt(String.valueOf(map.get("power"))));
		user.setCreateUser(currentUser);
		user.setCreateTime(currentTime);
		user.setModifyUser(currentUser);
		user.setModifyTime(currentTime);
		return userDao.insert(user);
	}

	@Override
	public boolean loginValidate(Map map) {
		// TODO Auto-generated method stub
		boolean flag =true;
		List<User> list = userDao.selectParam(map);
		if(list.size()<=0){
			flag=false;
		}
		return flag;
	}

	@Override
	public int updateUser(Map map) {
		// TODO Auto-generated method stub
		User user = new User();
		String currentUser = String.valueOf(map.get("currentUser"));
		String currentTime = ManageTimeUtil.getCurrentTime();
		user.setId(String.valueOf(map.get("id")));
		user.setUsername(String.valueOf(map.get("username")));
		user.setPassword(String.valueOf(map.get("password")));
		user.setNickname(String.valueOf(map.get("nickname")));
		user.setDepartID(String.valueOf(map.get("departID")));
		user.setDepartName(String.valueOf(map.get("groupName")));
		user.setPower(Integer.parseInt(String.valueOf(map.get("power"))));
		user.setModifyUser(currentUser);
		user.setModifyTime(currentTime);
		return userDao.update(user);
	}
}
